package xyz.fuqufyb.aec.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.fuqufyb.aec.data.JsonResult;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.Recharge;
import xyz.fuqufyb.aec.service.IRechargeService;

import java.util.Arrays;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: RechargeController
 * @date 时间: 2021/2/2 13:27
 *
 * 充值接口数据
 */

@RestController
@RequestMapping("/sys/recharge")
public class RechargeController {

    @Autowired
    private IRechargeService rechargeService;

    /**
     * 分页查询和模糊查询 充值数据
     * @param maps
     * @return
     */
    @RequestMapping("/table")
    public TableResult getTable(@RequestParam  Map<String,Object> maps){

        try {
            TableResult pageRecharge = rechargeService.getPageRecharge(maps);
            return pageRecharge;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return TableResult.getTableResultError();

    }

    /**
     * 新增 充值数据
     * @param recharge
     * @return
     */
    @PostMapping("/add")
    public JsonResult addRecharge(Recharge recharge) {
        int i = rechargeService.insertSelective(recharge);
        if (i > 0) {
            return JsonResult.getJsonSuccess("新增成功");
        }
        return JsonResult.getJsonError();

    }

    /**
     * 修改充值数据
     * @param recharge
     * @return
     */
    @PostMapping("/update")
    public JsonResult updateRecharge(Recharge recharge) {
        int i = rechargeService.updateByPrimaryKeySelective(recharge);
        if (i > 0) {
            return JsonResult.getJsonSuccess("更新成功");
        }
        return JsonResult.getJsonError();
    }

    /**
     * 批量删除 充值数据
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public JsonResult delRechargeIds(@RequestParam("ids") Integer[] ids) {
        int i = rechargeService.deleteByRechargeIds(Arrays.asList(ids));
        if (i > 0) {
            return JsonResult.getJsonSuccess("删除成功");
        }
        return JsonResult.getJsonError();
    }
}


